#ifndef bailian_MapEditor_h
#define bailian_MapEditor_h

#include "../PreInclude.h"
#include "../DevMacros.h"
#include "../utils/ByteBuffer.h"
#include "SceneToScene.h"
#include "MapInfo.h"
#include "GridInfo.h"
#include "NpcInfo.h"
#include "JumpInfo.h"
#include "MyAStar.h"
#include "RoadData.h"


//地图编辑器定义
const double EPSINON = 1E-6;
const int32 DEFAULT_CONTROLPANELWIDTH = 100;
const int32 DEFAULT_CONTROLPANELHEIGHT = 60;
const int32 DEFAULT_BUTTONHEIGHT = 30;
const int32 DEFAULT_GRIDLENGHT = 48;
const float DEFAULT_RATIO = 2.2f;
const float DEFAULT_GRIDHEIGHT = ((2 * DEFAULT_GRIDLENGHT) / pow(((DEFAULT_RATIO * DEFAULT_RATIO) + 1.0f), 0.5f));
const float DEFAULT_GRIDWIDTH = (DEFAULT_RATIO * DEFAULT_GRIDHEIGHT);
const int32 BIGGRIDLINE_COLOR = 16763080;
const int32 SMALLGRIDLINE_COLOR = 16744576;
const float Color_BlockFloor = 0xFF0000;
const float Color_TranslucentFloor = 0xFF00;
const float Color_BlockSightFloor = 0xFF;
const float Color_NpcFloor = 0x444444;
const float Color_MonsterFloor = 0x555555;
const float Color_JumppointFloor = 0x666666;
const float Color_BlockSky = 0x1111;
const float Color_TranslucentSky = 0x2222;
const float Color_BlockSightSky = 0x3333;
const float Color_NpcSky = 0x4444;
const float Color_MonsterSky = 0x5555;
const float Color_JumppointSky = 0x666666;



const uint32 GRID_BLOCK=1;
const uint32 GRID_BLOCKSIGHT=(1 << 1);
const uint32 GRID_TRANSLUCENT1=(1 << 2);
const uint32 GRID_TRANSLUCENT2=(1 << 3);
const uint32 GRID_TRANSLUCENT3=(1 << 4);
const uint32 GRID_TRANSLUCENT4=(1 << 5);
const uint32 GRID_TRANSLUCENT=GRID_TRANSLUCENT1;
const uint32 GRID_NPC=(1 << 6);
const uint32 GRID_MONSTER=(1 << 7);
const uint32 GRID_JUMPPOINT=(1 << 8);

const int32 NORMAL_BLOCK_WIDTH=256;
const int32 NORMAL_BLOCK_HEIGHT=256;
 

const int32 MAP_BLOCK_WIDTH=NORMAL_BLOCK_WIDTH;
const int32 MAP_BLOCK_HEIGHT=NORMAL_BLOCK_HEIGHT;


const int32 MAP_WIDTH_BLOCK_NUM = 20; //地图宽的多少个格子
const int32 MAP_HEIGHT_BLOCK_NUM = 20; //地图宽的多少个格子


const int32 STATE_FLOOR=0;
const int32 STATE_SKY=1;
const int32 PATROLRULE_STAND=0;
const int32 PATROLRULE_RAND=1;
const int32 PATROLRULE_OUTHOME=2;
const int32 PATROLRULE_ROUND=3;

class CMapEditor:public CCObject{
    
public:
    CMapEditor();
    virtual~CMapEditor();
    
    CREATE_FUNC(CMapEditor);
    
    virtual bool init(){ return true;  }
    
    void loadMap(string & cFilePath);
    
    CCPoint getIndexFromPos(float nX,float nY,float nWidth=-1,float nHeight=-1);
    
    int getPixelWidth();
    
    int getPixelHeight();
    
    DEV_PROPERTY( MyAStar* , m_pAStar, AStar);
    
    DEV_PROPERTY(SceneToScene* , m_pSceneToScene, SceneToScene);
    
    DEV_PROPERTY( CRoadData* , m_pRoadData, RoadData);
    
    CCPoint getAppropriateIndex( const CCPoint& targetPos,  const CCPoint& pos, uint32 nBlockNum=1, bool flag=true, int nZ=-1);
    
    bool getPosTranslucent(int nX, int nY, int nState=-1);
    
    bool isArrivalble(int nX,int nY,int nZ=-1);
    
    vector<JUMP_INFO> gJumpInfo;
    
    vector<NPC_INFO> gMonsterInfo;
    
    vector<NPC_INFO> gNpcInfo;
    
    vector<vector<GRID_INFO> >  gGridInfo;
    
    void clear();
    
    CCPoint findFromSouthWest(    CCPoint pos, uint32 nZ, uint32 nBlockNum);
    CCPoint findFromWest(CCPoint pos, uint32 nZ, uint32 nBlockNum);
    CCPoint findFromNorthWest( CCPoint pos, uint32 nZ, uint32 nBlockNum);
    CCPoint findFromNorth( CCPoint pos, uint32 nZ, uint32 nBlockNum);
    CCPoint findFromNorthEast(   CCPoint pos, uint32 nZ, uint32 nBlockNum);
    CCPoint findFromEast(    CCPoint pos, uint32 nZ, uint32 nBlockNum);
    CCPoint findFromSouthEast(    CCPoint pos, uint32 nZ, uint32 nBlockNum);
    CCPoint findFromSouth(    CCPoint pos, uint32 nZ, uint32 nBlockNum);
    
    
    CCPoint SOUTH(const CCPoint& pos, uint32 nNum=1);
    CCPoint EAST(const CCPoint& pos, uint32 nNum=1);
    CCPoint WEST(const CCPoint& pos, uint32 nNum=1);
    CCPoint NORTH(const CCPoint& pos, uint32 nNum=1);
    CCPoint SOUTHWEST(const CCPoint& pos, uint32 nNum=1);
    CCPoint SOUTHEAST(const CCPoint& pos, uint32 nNum=1);
    CCPoint NORTHWEST(const CCPoint& pos, uint32 nNum=1);
    CCPoint NORTHEAST(const CCPoint& pos, uint32 nNum=1);
    
     
    
    MAP_INFO m_tMapInfo;
    
    
};

#endif
